package com.yuan.dao.impl;

import com.yuan.pojo.User;
import com.yuan.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void updateUser(User user) {
        String sql = "UPDATE t_user SET username=?, password=?, nickname=? WHERE id=?";
        jdbcTemplate.update(
                sql,
                user.getUsername(),
                user.getPassword(),
                user.getNickname(),
                user.getId()
        );
    }

    @Override
    public void updatePwdByUsername(String username, String password) {
        String sql = "UPDATE t_user SET password=? WHERE username=?";
        jdbcTemplate.update(sql, password,username );
    }

    @Override
    public void updateNicknameByUsername(String nickname, String username) {
        String sql = "UPDATE t_user SET nickname=? WHERE username=?";
        jdbcTemplate.update(sql, nickname, username);
    }
}
